import React from 'react'
import PropTypes from 'prop-types'
import Component, { mapStateToProps, mapDispatchToProps } from '@components/Component'
import { connect } from 'react-redux'
import Approve from '@components/ApprovePre/Index'
import SecretaryInput from './Reduction/SecretaryInput'
import SecretaryHistory from './Reduction/SecretaryHistory'

class Reduction extends Component {
  // 获取表单初始化数据
  getFormInitialData (instance) {
    switch (instance.currentStep.step_key) {
      case 'jianmian01':
        return { vars: { claimid: this.props.caseDetail.claim.id } }
      default:
        return {}
    }
  }

  // 渲染当前操作步骤线上部分
  renderCurrentStepLineTop (formRef, instance, renderFn) {
    switch (instance.currentStep.step_key) {
      case 'jianmian01':
        return <SecretaryInput instance={instance} userInfo={this.props.userInfo} caseDetail={this.props.caseDetail} formRef={formRef} />
      default:
        return renderFn()
    }
  }

  // 渲染历史
  renderHistory (action, renderFn, instance, renderDoc) {
    const key = action.step_key
    // const isDisagree = action.opt_add === 'disagree'
    if (key === 'jianmian01') {
      return <SecretaryHistory key={action.id} userInfo={this.props.userInfo} instance={instance} action={action} caseDetail={this.props.caseDetail} renderDoc={renderDoc} />
    }
    return renderFn(action)
  }

  render () {
    return (
      <div>
        <Approve
          caseDetail={this.props.caseDetail}
          flowKey='jianmian'
          afterAction={(instance, action) => this.props.refreshCaseData()}
          creatable={this.props.editable}
          renderCurrentStepLineTop={(...params) => this.renderCurrentStepLineTop(...params)}
          renderHistory={(h, renderFn, instance, renderDoc) => this.renderHistory(h, renderFn, instance, renderDoc)}
          initialCurrentStepFormData={instance => this.getFormInitialData(instance)}
          setBizid={() => Promise.resolve(this.props.caseDetail.claim.id)}
          // beforeSubmit={(...params) => this.beforeSubmit(...params)}
          multiply
        />
      </div>
    )
  }
}

Reduction.propTypes = {
  // caseDetail: PropTypes.object,
  // active: PropTypes.bool,
  refreshCaseData: PropTypes.func,
  editable: PropTypes.bool
  // fileList: PropTypes.array
  // getFileList: PropTypes.func
}
Reduction.defaultProps = {
  caseDetail: {},
  active: false,
  refreshCaseData: () => {},
  editable: false,
  fileList: [],
  getFileList: () => {}
}

const mapState = mapStateToProps(function (state) {
  return {
    userInfo: state.basic.userInfo
  }
})

const mapDispatch = mapDispatchToProps(function (dispatch) {
  return {

  }
})

export default connect(mapState, mapDispatch)(Reduction)
